/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author antonio
 */
@Entity
//@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "Construct")
//@DiscriminatorColumn(name = "construct_type", discriminatorType = DiscriminatorType.STRING)
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Construct.findAll", query = "SELECT c FROM Construct c"),
    @NamedQuery(name = "Construct.findByName", query = "SELECT c FROM Construct c WHERE c.name = :name")})
public class Construct implements Serializable {
    
    @Lob
    @Column(name = "img")
    private byte[] img;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "construct1")
    private Collection<ProductionCost> productionCostCollection;

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @NotNull
    @Column(name = "build_time")
    private int buildTime;
    @Basic(optional = false)
    @NotNull
    @Column(name = "production_time")
    private int productionTime;
    @ManyToMany(mappedBy = "constructCollection")
    private Collection<Era> eraCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "construct1")
    private Collection<Cost> costCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "construct1")
    private Collection<Ownership> ownershipCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "construct1")
    private Collection<Production> productionCollection;
    @Column(name = "init_amount")
    private Integer initAmount;

    public Construct() {
    }

    public Construct(String name) {
        this.name = name;
    }

    public Construct(String name, int buildTime, int productionTime) {
        this.name = name;
        this.buildTime = buildTime;
        this.productionTime = productionTime;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBuildTime() {
        return buildTime;
    }

    public void setBuildTime(int buildTime) {
        this.buildTime = buildTime;
    }

    public int getProductionTime() {
        return productionTime;
    }

    public void setProductionTime(int productionTime) {
        this.productionTime = productionTime;
    }

    @XmlTransient
    public Collection<Era> getEraCollection() {
        return eraCollection;
    }

    public void setEraCollection(Collection<Era> eraCollection) {
        this.eraCollection = eraCollection;
    }
    
    @XmlTransient
    public Collection<Production> getProductionCollection() {
        return productionCollection;
    }

    public void setProductionCollection(Collection<Production> productionCollection) {
        this.productionCollection = productionCollection;
    }

    @XmlTransient
    public Collection<Cost> getCostCollection() {
        return costCollection;
    }

    public void setCostCollection(Collection<Cost> costCollection) {
        this.costCollection = costCollection;
    }

    @XmlTransient
    public Collection<Ownership> getOwnershipCollection() {
        return ownershipCollection;
    }

    public void setOwnershipCollection(Collection<Ownership> ownershipCollection) {
        this.ownershipCollection = ownershipCollection;
    }

    public Integer getInitAmount() {
        return initAmount;
    }

    public void setInitAmount(Integer initAmount) {
        this.initAmount = initAmount;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (name != null ? name.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Construct)) {
            return false;
        }
        Construct other = (Construct) object;
        if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Construct[ name=" + name + " ]";
    }

    public byte[] getImg() {
        return img;
    }

    public void setImg(byte[] img) {
        this.img = img;
    }

    @XmlTransient
    public Collection<ProductionCost> getProductionCostCollection() {
        return productionCostCollection;
    }

    public void setProductionCostCollection(Collection<ProductionCost> productionCostCollection) {
        this.productionCostCollection = productionCostCollection;
    }
    
}
